<?php echo $header; ?>

<div id="content" class="w-content">
    <div class="eachBox undepages produkter-2">
        <div class="wrap-top clearfix">
            <ul class="breakcum">
                <?php foreach ($breadcrumbs as $breadcrumb) { ?>
                    <?php if($breadcrumb['href']) { ?>
                        <li><a href="<?php echo $breadcrumb['href']; ?>" title="<?php echo $breadcrumb['text']; ?>"><?php echo $breadcrumb['text']; ?> </a></li>
                    <?php }else { ?>
                        <li><a href="javascript:void(0);" title="<?php echo $breadcrumb['text']; ?>"><?php echo $breadcrumb['text']; ?> </a></li>
                    <?php } ?>
                <?php } ?>
            </ul>
            <div class="sortPro">
                <span><?php echo $text_sort; ?></span>
                <select class="sort_products-1" name="sort" onchange="location = this.value">
                    <?php foreach ($sorts as $sort_item) { ?>
                        <?php if (($sort . '-' . $order) == $sort_item['value']) { ?>
                            <option value="<?php echo $sort_item['href']; ?>" selected="selected"><?php echo $sort_item['text']; ?></option>
                        <?php } else { ?>
                            <option value="<?php echo $sort_item['href']; ?>"><?php echo $sort_item['text']; ?></option>
                        <?php } ?>
                    <?php }?>
                </select>

                <?php $attr = current($attributes); ?>
                <?php if($attr['attribute_values']){        //if($attributes){ ?>
                    <span>Efter størrelse</span>
                    <select class="sort_products-2" name="product_size" onchange="location = this.value">
                        <?php foreach ($attributes as $attribute) { ?>
                            <option value="<?php echo $filter_size . '0'; ?>">- Alle -</option>
                            <?php foreach ($attribute['attribute_values'] as $attribute_value) { ?>
                                <?php if ($attribute_value['value_id'] == $current_size) { ?>
                                    <option value="<?php echo $filter_size . $attribute_value['value_id']; ?>" selected="selected"><?php echo $attribute_value['name']; ?></option>
                                <?php } else { ?>
                                    <option value="<?php echo $filter_size . $attribute_value['value_id']; ?>"><?php echo $attribute_value['name']; ?></option>
                                <?php } ?>
                            <?php } ?>
                        <?php } ?>
                    </select>
                <?php } ?>
            </div>
        </div>
        <!-- wrap-top -->
        <h4 class="box_tt"><?php echo $heading_title ?></h4>
        <div><?php echo $description ?></div>
    </div>
    <!-- undepages produkter-2 -->

    <div id="product_list" class="eachBox wrap-list-prod clearfix">
        <ul id="product_loaded<?php echo $lazy_load['page'] ?>" class="listProd">
            <?php $i = 0; ?>
            <?php foreach ($products as $product) { ?>
                <li>
                    <a href="#" class="product">
                        <?php if($product['discount']){ ?>
                            <div class="sale-off"><span>-<?php echo $product['rate_discount'];?></span><span>%</span></div>
                        <?php } ?>
                        <?php $href = str_replace('&', '&amp;', $product['href']); ?>
                        <a class="prod-img" href="<?php echo $href; ?>">
                            <img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>"/>
                        </a>
                        <div class="prod-name"><p><?php echo $product['name']; ?> </p></div>
                        <div class="prod-price">
                            <?php if($product['discount']){ ?>
                                <span class="price-old"> <?php echo $product['price']; ?></span><span class="price-new"><?php echo $product['discount']; ?></span>
                            <?php }else{ ?>
                                <span class="price-normal"><?php echo $product['price']; ?></span>
                            <?php } ?>
                        </div>

                        <?php if($product['options'] && false) { ?>
                        <div class="product_sizes_popup">
                            <?php
                            $op = 0;
                            foreach($product['options'] as $options){
                                $option_data = '';
                                foreach($options['option_value'] as $option_item){
                                    $option_data .=  $option_item['name'] . ', ';
                                }
                                $option_data = trim($option_data, ', ');
                            ?>

                                <p class="header <?php echo ($op > 0 ? ' p5t' : ''); ?>"><?php echo (strcasecmp($options['name'], 'Størrelse') == 0) ? 'Størrelser' : $options['name'] ?></p>
                                <p class="data"><?php echo $option_data ?></p>
                                <?php $op++; ?>
                            <?php } ?>
                        </div>
                        <?php } ?>

                        <a href="<?php echo $href; ?>" class="btn btnBestil">Bestil Nu</a>
                        <div class="see-inc"><a class="hastool" title="<?php echo $shipping_note; ?>">Se pris inkl. fragt/gebyr</a></div>
                    </a>
                </li>

                <?php $i++; ?>
            <?php } ?>
        </ul>

        <div id="lazy_loading" class="lazy_loading">
            <a id="load_next_page" href="#">
                <span>Se flere produkter</span>
                <img src="catalog/view/theme/<?php echo $template; ?>/images/lazyload14.gif"/>
            </a>
        </div>
    </div>
    <!-- wrap-list-prod -->

    <?php echo $services ?>

    <?php echo $newsletter ?>

<script type="text/javascript">
    var page = <?php echo $lazy_load['page'] ?>;
    var limit = <?php echo $lazy_load['limit'] ?>;
    var total = <?php echo $lazy_load['total'] ?>;
    var url = '<?php echo $lazy_load['url']?>&lazy_load=1';

    $(window).scroll(function() {
        var pos = $(window).scrollTop();
        var windowHeight = $(window).height();
        var footer = Math.round($('#footer').offset().top);
        var loadingId = '#lazy_loading';


        $(loadingId).hide();
        if((pos + windowHeight > footer - 100) && ((page) * limit < total)){
            $(loadingId).show();
        }
    });

    $('#load_next_page').on('click', function(e){
        e.preventDefault();

        var data = {
            "page":             page,
            "limit":            limit,
            "total":            total,
            "url":              url,

            "loading_id":       'lazy_loading',
            "result_id":        'product_list ul:last'
        }

        page = lazyLoad(data);
    })
</script>

<?php echo $footer; ?>